# handler_login.py
#
#

""" handlers login requests. redirects to a google url for now. """

# set start time

import time
starttime = time.time()

## gozerlib imports

from gozerlib.utils.generic import fromenc, toenc, getversion
from gozerlib.utils.web import start, closer
from gozerlib.utils.auth import checkuser

## google imports

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from google.appengine.api import users as gusers

## basic imports

import wsgiref.handlers
import sys
import time
import types
import os
import logging

logging.basicConfig(level=logging.INFO)
logging.info(getversion('LOGIN'))

class LoginHandler(webapp.RequestHandler):

    """ the bots web command dispatcher. """


    def get(self):

        """ show basic page. """

        self.response.starttime = starttime
        start(self.response)
        self.response.out.write('<div class="body">')
        plzlogin = ("<a href=\"%s\">Sign in or register</a>." %
        gusers.create_login_url("/"))
        self.response.out.write(plzlogin)
        self.response.out.write("</div>")
        closer(self.response)

# the application 

application = webapp.WSGIApplication([('/login', LoginHandler),
                                      ('/login/', LoginHandler)],
                                      debug=True)

def main():
    global application
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
